<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
</head>
<script>
    $.ajaxSetup({
        async: false
    });
    $(function(){
        $(".layui-bg-red").click(function(){
            $("#tsone").html("");
            $("#tstwo").html("");
        });

    })
</script>
<body>
<form class="layui-form layui-form-pane" id="formDId" action="" method="post" enctype="multipart/form-data">
    <input type="hidden" name="pkClientId" id ="pkClientId" />
    <div class="layui-form-item">
        <label class="layui-form-label">客户名称</label>
        <div class="layui-input-block">
            <input type="text" name="clientName" id ="clientName" lay-verify="required" autocomplete="off" placeholder="客户名称(必填)"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 120px;">纳税人识别号</label>
        <div class="layui-input-block" style="margin-left: 120px">
            <input type="text" name="clientTaxpayer" id = "clientTaxpayer" autocomplete="off" class="layui-input" lay-verify="required" placeholder="请输入纳税人识别号">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">客户类型</label>
        <div class="layui-input-block">
            <div id="clientTypeId" class="xm-select-demo" ></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户编码</label>
        <div class="layui-input-block">
            <input type="text" name="clientCode" placeholder="请输入客户编码" lay-verify="required" id = "clientCode" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">开户行</label>
        <div class="layui-input-block">
            <input type="text" name="clientBank" id = "clientBank" autocomplete="off" lay-verify="required" class="layui-input" placeholder="请输入开户行">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">银行账号</label>
        <div class="layui-input-block">
            <input type="text" name="bankCode" id = "bankCode" autocomplete="off" class="layui-input" lay-verify="required|number"  placeholder="请输入银行账号" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
        <input type="text" class="layui-input" id="clientEmail" name="clientEmail"lay-verify="email"   placeholder="请输入邮箱">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="clientPhone" name="clientPhone" lay-verify="phone" placeholder="请输入联系电话" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">住址</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="clientSite" name="clientSite" lay-verify="required"  placeholder="请输入住址">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">提交</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
        </div>
    </div>

<script>

    //需要操作的数据
    let clientId = getQueryString("pkClientId");
    let clientTypeId;
    let show = getQueryString("show");
    layui.use(['form', 'laydate','upload'], function () {
        var form = layui.form
            , laydate = layui.laydate;
        var $ = layui.jquery
            ,upload = layui.upload;
        if(clientId){
            let client=getAjaxById(getRootPath()+"OaClientAction/findById/"+clientId);
            clientTypeId = client.data.clientTypeId;
            $("#pkClientId").val(client.data.pkClientId);
            $("#clientName").val(client.data.clientName);
            $("#clientTaxpayer").val(client.data.clientTaxpayer);
            $("#clientTypeId").val(client.data.clientTypeId);
            $("#clientBank").val(client.data.clientBank);
            $("#bankCode").val(client.data.bankCode);
            $("#clientCode").val(client.data.clientCode);
            $("#clientEmail").val(client.data.clientEmail);
            $("#clientPhone").val(client.data.clientPhone);
            $("#clientSite").val(client.data.clientSite);
        }

        //加载组件
        layui.config({
            //引入扩展文件库
            base: getRootPath()+'res/layui/dist/'
        }).extend({
            //引入对应的文件名
            xmSelect: 'xm-select'
            //拿到对应的文件模块
        }).use(['xmSelect'], function(){
            //对于模块赋值使用
            var xmSelect = layui.xmSelect;
            //渲染多选
            pkJurisdictionId = xmSelect.render({
                el: '#clientTypeId',
                radio: true,
                layVerify: 'required',
                tree: {
                    show: true,
                    strict: false,
                    expandedKeys: [ -1 ],
                },
                height: 'auto',
                data: loadOaClientType(clientTypeId,show)
            })

        });
        function loadOaClientType(id,show){
            let url = getRootPath()+"OaClientTypeAction/loadOaClientType";
            let data = {
                id : id, //需要操作的数据
                show:'2'
            };
            let res = getAjax(url,data);
            if(res){
                return res;
            }else{
                return [];
            }

        }


        //监听起草提交
        form.on('submit(demo1)', function (data) {

            console.info(data.field);
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var formData = new FormData(document.getElementById("formDId"));
            console.log(formData)
            let res = postAjaxFile(getRootPath() + "OaClientAction/addOrUpdate", formData);
            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3000);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {
                error('500');
            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });
    });



</script>
</form>
</body>
</html>